<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        .box {
            margin: 20px 10px;
            width: 200px;
            height: 30px;
            border-bottom: 1px solid#ccc;
        }

        .box input {
            width: 160px;
            height: 30px;
            outline: none;
            padding: 0 2px;
            border:0;
            border-bottom: 1px solid #ccc;
        }

        .box img {
            width: 24px;
            height: 30px;
            vertical-align:bottom;
        }
    </style>
</head>

<body>

    <button>1.按钮操作</button>
    <input type="text" value="输入内容">

    <div class="box">
        <input type="password" id="pwd">
        <label for="">
            <img src="images/close.png" alt="" id="eye">
        </label>
    </div>
    <script>
        //1.文本框操作
        var btn = document.querySelector('button');
        var input = document.querySelector('input');
        btn.onclick = function () {
            input.value = '点击我干嘛';
            //this指向时间函数的调用者 btn
            this.disabled = true;
        }

        //2.隐藏密码明文案例
        var pwd = document.querySelector('#pwd');
        var eye = document.querySelector('#eye');
        var flag = 0;
        eye.onclick = function() {
            if(flag == 0){
                pwd.type = 'password';
                this.src = 'images/close.png';
                flag = 1;
            }else{
                pwd.type= 'text';
                this.src = 'images/open.png';
                flag = 0;
            }
        }
    </script>
</body>

</html>